﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;

namespace Quản_Lý_Thư_Viện
{
    class PhanquyenDataAccess
    {
        private DataProvider _provider = new DataProvider();
        public PhanquyenDataAccess()
        {
            _provider.connect();
        }
        public void insertphanquyenDG(PhanquyenInfo info)
        {
            string insertCommand = "insert into dbo.PHANQUYEN values('" + info.Mataikhoan + "','" + info.Matkhau + "','0')";
            _provider.executeNonQuery(insertCommand);
        }
        public void insertphanquyenNV(PhanquyenInfo info)
        {
            string insertCommand = "insert into dbo.PHANQUYEN values('" + info.Mataikhoan + "','" + info.Matkhau + "','1')";
            _provider.executeNonQuery(insertCommand);
        }
        public void updatephanquyen(PhanquyenInfo info)
        {
            string updateCommand = "update dbo.PHANQUYEN set MATAIKHOAN = '" + info.Mataikhoan
                + "',MATKHAU = '" + info.Matkhau + "',QUYEN = " + info.Quyen + " where MATAIKHOAN = '" + info.Mataikhoan + "'";
            _provider.executeNonQuery(updateCommand);
        }
        public void deletephanquyen(PhanquyenInfo info)
        {
            string deleteCommand = "delete from dbo.PHANQUYEN where MATAIKHOAN = '" + info.Mataikhoan + "'";
            _provider.executeNonQuery(deleteCommand);
        }
        public DataTable laydsphanquyen()
        {
            return _provider.GetData("select * from dbo.PHANQUYEN where MATAIKHOAN = '" + FrmDangNhap.txt1 + "' AND MATKHAU = '" + FrmDangNhap.txt2 + "'");
        }
        public void updatematkhau(PhanquyenInfo info)
        {
            string updateCommand = "update dbo.PHANQUYEN set MATKHAU = '"+info.Matkhau+"' where MATAIKHOAN = '"+FrmDangNhap.txt1+"'";
            _provider.executeNonQuery(updateCommand);
        }

    }
}
